package com.kaili.basic.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.pojo.dto.*;
import com.kaili.basic.pojo.entity.BaseStoreLocationEntity;
import com.kaili.basic.pojo.vo.BaseStoreLocationVO;
import com.kaili.basic.service.BaseStoreLocationService;
import com.kaili.basic.version.ApiVersion;
import com.kaili.common.aop.OperateLogAspect;
import com.kaili.common.aop.log.enums.FunctionName;
import com.kaili.common.aop.log.enums.OperateType;
import com.kaili.common.exception.RestException;
import com.kaili.common.response.CommonStatus;
import com.kaili.common.response.RestStatus;
import com.kaili.common.util.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.util.*;

/**
 * @author lsw
 * @Type BaseStoreHouse
 * @Desc 杭州凯立通信有限公司Controller
 * @Date 2019年03月07日
 */
@ApiVersion(1)
@RestController
@RequestMapping("/{api_version}")
@Transactional
@Api(tags = "库位管理", description = "库位管理")
public class BaseStoreLocationController {
    @Autowired
    private BaseStoreLocationService baseStoreLocationService;

    @PostMapping("/storeLocation")
    @ApiOperation(value = "新增库位")
    @OperateLogAspect(functionName = FunctionName.location,operateType = OperateType.ADD, key = "storeLocationName")
    public RestStatus addStoreLocation(@RequestBody BaseStoreLocationAddDto addDto){
        BaseStoreLocationEntity entity=new BaseStoreLocationEntity();
        entity.setCreateTime(new Date());
        entity.setCreateBy(2);
        BeanUtils.copyProperties(addDto,entity);
        baseStoreLocationService.insert(entity);
        return CommonStatus.ADD_OK;
    }

    @PutMapping("/storeLocation")
    @OperateLogAspect(functionName = FunctionName.location,operateType = OperateType.UPDATE, key = "storeLocationName")
    @ApiOperation(value = "修改库位")
    public RestStatus updateStoreLocation(@RequestBody BaseStoreLocationAddDto addDto){
        BaseStoreLocationEntity entity=new BaseStoreLocationEntity();
        entity.setModifyTime(new Date());
        entity.setModifyBy(2);
        BeanUtils.copyProperties(addDto,entity);
        baseStoreLocationService.updateById(entity);
        return CommonStatus.UPDATE_OK;
    }

    @DeleteMapping("/storeLocation/{id}")
    @ApiOperation(value = "删除库位")
    @OperateLogAspect(functionName = FunctionName.location,operateType = OperateType.DELETE)
    public RestStatus delStoreLocation(@PathVariable("id") Integer id){
        baseStoreLocationService.deleteById(id);
        return CommonStatus.DELETE_OK;
    }

}
